package com.stu.aq;


import com.stu.usb.SerialIOManager;

import android.app.Fragment;

public abstract class CommandFragment extends Fragment {
	protected OnCommandListener mListener;

	public enum FragmentState {
		UPDATING, STOPPING, WRITING
	}

	public interface OnCommandListener {
		/**
		 * This will be called after receiving the command result string
		 *   from the copter.
		 * Typically called from the frament UI update so it is on the UI thread.
		 * @param fragmentId The id of the fragment that interpreted the command.
		 * @param state Info about the state of the fragment
		 */
		public void OnCommandComplete( final int fragmentId, final FragmentState state );
		/**
		 * If the command parser encounters an error it will call this.
		 * Typically called from the IO handler so not on the UI thread.
		 * @param fragmentId The id of the fragment that interpreted the command.
		 * @param e The exception with the error info.
		 */
		public void OnCommandError( final int fragmentId, final AQException e );
		/**
		 * Called if the command parser encounters a non-fatal error
		 * @param fragmentId The id of the fragment that interpreted the command.
		 * @param e The exception with the error info.
		 */
		public void OnCommandWarning( final int fragmentId, final AQException e );
	}

	/**
	 * Ask the fragment to get status from the copter and update it's widgets.
	 * @param l The listener to be called when the update is complete.
	 * @param io The IOManager
	 */
	abstract public void update( OnCommandListener l, SerialIOManager io );

	/**
	 * Called from StatusManager on the UI thread
	 * @param statusData Data for the fragment UI
	 */
	abstract public void updateUI( Object statusData );

	/**
	 * Stop constant updates to this fragment
	 * @param l The listener to be called when the stop is complete
	 * @param io The IOManager
	 */
	abstract public void stopUpdate( OnCommandListener l, SerialIOManager io );
	
	/**
	 * Write the current values to the copter
	 * @param l The listener to be called when the stop is complete
	 * @param io The IOManager
	 */
	abstract public void write( OnCommandListener l, SerialIOManager io );
	
	/**
	 * Clear all fields
	 */
	abstract public void clear();
}
